home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-screenplay-
/
shareware
/
scott
/
source
/
source.lha
/
AMIGA6.C
next >
Wrap
C/C++ Source or Header
|
1999-04-04
|
45KB
|
1,672 lines
/*
* AMIGA Libs & Functions for Scott-Free
*
* ===================================================================
*
* Version History AMIGA:
* Ver , Date, Author, Comment
* -------------------------------------------------------------------
* 1.0 , 28/07/96, Andreas Aumayr, First public release
* 1.1 , 16/08/96, Andreas Aumayr, Added ToolType support & font prefs
* 1.2 , 30/08/96, Andreas Aumayr, ASL-FR for Load/Save/Datafile
* 1.3 , 08/09/96, Andreas Aumayr, Menus, loads of minor enhancements,
* 'real' command history, more TTs
* 1.4 , 17/09/96, Andreas Aumayr, Public screen support, more TTs, ..
* 1.5 and higher: Andreas Aumayr, just to lazy to keep track of changes :-)
* ___________________________________________________________________
*/
#define MAX_HIST 20
#define MAX_LL 40
#define PIC 8
#define COC 7
#define OVL 6
#define ANI 5
#define GOT 4
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <time.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <graphics/GfxBase.h>
#include <graphics/rpattr.h>
#include <workbench/workbench.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <dos/exall.h>
#include <utility/tagitem.h>
#include <libraries/asl.h>
#include <libraries/gadtools.h>
#include <workbench/startup.h>
#include <libraries/amigaguide.h>
#include <datatypes/pictureclass.h>
#include <devices/inputevent.h>
#include <exec/types.h>
#include <exec/exec.h>
#include <devices/narrator.h>
#include <libraries/translator.h>
#include "gui.c"
extern struct MsgPort *CreatePort();
extern struct IORequest *CreateExtIO();
ULONG TranslatorBase;
struct MsgPort *narratorPort;
struct narrator_rb *request;
STRPTR nartrans[1024];
ULONG narBuf;
BYTE channels[4] = {3,5,10,12};
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
ULONG DiskfontBase;
ULONG IconBase;
ULONG Dos_Base;
ULONG UtilityBase;
ULONG AslBase;
ULONG GadToolsBase;
ULONG AmigaGuideBase;
ULONG DataTypesBase;
struct Screen *WBscreen = NULL;
struct Screen *ScottScreen = NULL;
ULONG old_pubmode;
struct Window *act_w_hdl;
struct Window *pic_w_hdl = NULL;
APTR WBvisinfo = NULL;
struct TextFont *textfont = NULL;
char save_game[32] = "";
char data_file[32] = "",data_dir[256] = "";
char save_dir[256] = "";
char gfx_file[256] = "";
char FFP[256];
char hist[MAX_HIST][MAX_LL+1];
int hist_pos=0,hist_fill=0;
struct Menu *menu = NULL;
char Version[] = "$VER: AMIGA SCOTT-Free V1.8, 1996-99";
char GameInfoStr[256] = "";
struct WBStartup *WBMessage;
struct MsgPort *OldUserPort;
BOOL WBSTART = FALSE;
BOOL RESTART = TRUE;
BOOL LINEWRAP = TRUE;
BOOL GFX = TRUE;
BOOL SPEECH = FALSE;
ULONG Disp_ID;
BOOL FASTCOLOURS = FALSE;
//BOOL NOGFXPOS = FALSE;
//BOOL INIT = FALSE;
//BOOL GFXDOUBLE = FALSE;
char restart_file[42] = "RAM:";
BPTR restart_lock;
struct NewAmigaGuide scott_guide = {NULL};
int last_pic = -128;
room_pics *rp = 0;
ULONG *go = 0;
LONG Pens[16] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
UBYTE NumColours = 0;
UBYTE planesN = 0;
struct ColorRegister CR[16];
struct BitMap bitmapN;
int gfx_width = 0,gfx_height = 0;
WORD win_pos_ver,win_pos_hor;
int win_width = -1,win_height;
BYTE ScreenAspect;
UBYTE *picture = 0,*rle_dat = 0,*overlay = 0;
WORD w_top;
int nroom;
FILE *gfx_in_file;
/// NoSpeech
void NoSpeech(BYTE status)
{
switch(status) {
case 0:
CloseDevice(request);
case 1:
DeleteExtIO(request);
case 2:
DeletePort(narratorPort);
case 3:
CloseLibrary(TranslatorBase);
TranslatorBase = 0;
SPEECH = FALSE;
}
}///
/// close_libs
void close_libs(void)
{
if (TranslatorBase) NoSpeech(0);
if (AmigaGuideBase) CloseLibrary(AmigaGuideBase);
if (GadToolsBase) CloseLibrary(GadToolsBase);
if (AslBase) CloseLibrary(AslBase);
if (UtilityBase) CloseLibrary(UtilityBase);
if (Dos_Base) CloseLibrary(Dos_Base);
if (IconBase) CloseLibrary(IconBase);
if (DiskfontBase) CloseLibrary(DiskfontBase);
if (GfxBase) CloseLibrary(GfxBase);
if (IntuitionBase) CloseLibrary(IntuitionBase);
}///
/// open_libs
BOOL open_libs(void)
{
IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",37);
if (IntuitionBase == NULL) {
printf("Problems opening Intuition-Lib!\n");
return(FALSE);
}
GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",37);
if (GfxBase == NULL) {
printf("Problems opening GFX-Lib!\n");
return(FALSE);
}
DiskfontBase = OpenLibrary("diskfont.library",0);
if (DiskfontBase == 0) {
EasyRequest(NULL,&Library,NULL,"DiskFont");
return(FALSE);
}
IconBase = OpenLibrary("icon.library",0);
if (IconBase == 0) {
printf("Problems opening Icon-Lib!\n");
return(FALSE);
}
Dos_Base = OpenLibrary("dos.library",0);
if (Dos_Base == 0) {
printf("Problems opening DOS-Lib!\n");
return(FALSE);
}
UtilityBase = OpenLibrary("utility.library",0);
if (UtilityBase == 0) {
printf("Problems opening Utility-Lib!\n");
return(FALSE);
}
AslBase = OpenLibrary("asl.library",0);
if (AslBase == 0) {
EasyRequest(NULL,&Library,NULL,"ASL");
return(FALSE);
}
GadToolsBase = OpenLibrary("gadtools.library",36);
if (GadToolsBase == 0) {
printf("Problems opening GadTools-Lib!\n");
return(FALSE);
}
AmigaGuideBase = OpenLibrary("amigaguide.library",0);
TranslatorBase = OpenLibrary("translator.library",0);
if (TranslatorBase) {
narratorPort = (struct MsgPort *) CreatePort(0,0);
if (narratorPort == NULL) NoSpeech(3);
else {
request = (struct narrator_rb *) CreateExtIO(narratorPort, sizeof(struct narrator_rb));
if (request == NULL) NoSpeech(2);
else if (OpenDevice("narrator.device",0,request,0)) NoSpeech(1);
}
}
return(TRUE);
}///
///FreeGFXRes
void FreeGFXRes(void)
{
int i;
if (gfx_in_file) fclose(gfx_in_file);
if (rp) free(rp);
if (go) free(go);
if (FASTCOLOURS) for (i=0;i<NumColours;i++) SetRGB4(&WBscreen->ViewPort,i,(Pens[i]&0x0F00)>>8,(Pens[i]&0x00F0)>>4,Pens[i]&0x000F);
else {
for (i=0; i<NumColours; i++) {
if (Pens[i] > 0) ReleasePen(WBscreen->ViewPort.ColorMap,Pens[i]);
else break;
}
}
for (i=0; i<planesN; i++) {
if (bitmapN.Planes[i]) FreeRaster(bitmapN.Planes[i],gfx_width,gfx_height);
else break;
}
if (picture) FreeMem(picture,gfx_width*gfx_height);
if (rle_dat) FreeMem(rle_dat,gfx_width*gfx_height);
if (overlay) FreeMem(overlay,gfx_width*gfx_height);
}///
/// close_all
void close_all(void)
{
if (restart_lock) UnLock(restart_lock);
DeleteFile(restart_file);
if (menu) FreeMenus(menu);
if (WBvisinfo) FreeVisualInfo(WBvisinfo);
if (WBscreen) UnlockPubScreen(NULL,WBscreen);
if (textfont) CloseFont(textfont);
if (pic_w_hdl) CloseWindow(pic_w_hdl);
if (act_hdl) {
act_w_hdl->UserPort = OldUserPort;
Close(act_hdl);
}
if (env_hdl) Close(env_hdl);
if (GFX) FreeGFXRes();
SetPubScreenModes(old_pubmode);
if (ScottScreen) {
while (CloseScreen(ScottScreen) == FALSE) EasyRequest(NULL,&ClosePub,NULL,NULL);
}
close_libs();
}///
/// MemAlloc
void * MemAlloc(int size)
{
void *t = (void *) AllocMem(size,MEMF_ANY|MEMF_CLEAR);
if (t == NULL) {
printf("\nUnable to get some mem!\nTerminating.\n");
EasyRequest(NULL,&NoMem,NULL,NULL);
close_all();
exit(128);
}
return(t);
}///
/// Open_CON
struct FileHandle *Open_CON(char *type, int left_off, int top_off, int width, int height, char *title, char *flags, char *cscreen)
{
sprintf(str_buf,"%s:%d/%d/%d/%d/%s/%s/SCREEN %s",type,left_off,top_off,width,height,title,flags,cscreen);
CON_handle = (struct FileHandle *) Open(str_buf,MODE_NEWFILE);
if (!CON_handle) {
printf("Failed to open console window '%s'!\n",title);
EasyRequest(NULL,&ConFail,NULL,title);
close_all();
exit(99);
}
else return(CON_handle);
}///
///dyn_strings
void * dyn_strings(char *cont, BYTE add)
{
void *mem_ptr;
if (cont && strlen(cont)) {
mem_ptr = Mem